package com.zs.controller;

import com.google.gson.Gson;
import com.zs.common.config.ResponseCode;
import com.zs.model.WorkLogEntity;
import com.zs.model.criteria.BaseCriteria;
import com.zs.service.MessageService;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 信息中心
 */
@Controller
@RequestMapping("/message")
public class WorkLogController {

    @Resource
    private Gson gson;

    @Resource
    private MessageService messageService;

    @RequestMapping(value = "list", method = RequestMethod.POST)
    @ResponseBody
    public String selectMessageList(HttpServletRequest request,
                                    @RequestParam(value = "pn", required = true, defaultValue = "1") Integer pageNo,
                                    @RequestParam(value = "ps", required = true, defaultValue = "3") Integer pageSize,
                                    Integer messageStatus
    ) {
    	System.out.println(messageStatus);
        BaseCriteria baseCriteria = new BaseCriteria();
        baseCriteria.setPageNo(pageNo);
        baseCriteria.setPageSize(pageSize);
        baseCriteria.setStatus(messageStatus);
        String messageListJson = messageService.selectMessageList(baseCriteria);
        return messageListJson ;
    }
    
    @RequestMapping(value = "add",method=RequestMethod.POST)
    @ResponseBody
    public String saveMessage(WorkLogEntity workLogTo){
    	Integer i = messageService.saveMessage(workLogTo);
    	if(i==1){
    		return gson.toJson(ResponseCode.DATA_SUCESS);
    	}else{
    		return gson.toJson(ResponseCode.DATA_FAIL);
    	}
    	
    }
    
}
